package com.cosin.model.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

public enum UserIdentity {
	/**
	 * 普通用户
	 */
	USER("USER"),

	/**
	 * 管理员角色
	 */
	ADMIN("ADMIN");

	private final String name;

	UserIdentity(String name) {
		this.name = name;
	}

	@JsonValue
	@Override
	public String toString() {
		return name;
	}

	@JsonCreator
	public static UserIdentity fromString(String value) {
		for (UserIdentity role : UserIdentity.values()) {
			if (role.name.equalsIgnoreCase(value)) {
				return role;
			}
		}
		throw new IllegalArgumentException("未知的角色: " + value);
	}
}
